package org.skipper.samples.spring.transaction.service;

import org.skipper.samples.spring.transaction.entity.UserInfo;
import org.skipper.samples.spring.transaction.enums.GenderEnum;
import org.skipper.samples.spring.transaction.mapper.UserInfoMapper;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author shoujian
 * Date: 2022-02-12
 * Time: 3:48 PM
 */
@Component
@Transactional(propagation = Propagation.REQUIRED)
public class TransactionalService {

    @Resource
    private PropagationService propagationService;

    @Resource
    private UserInfoMapper userInfoMapper;

    @Transactional(propagation = Propagation.REQUIRED)
    public void neverTransactionals() {
        propagationService.neverTransactional();
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void mandatoryTransactionals() {
        propagationService.mandatoryTransactional();
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void notSupportedTransactionals() {
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(34L);
        userInfo.setNickname("昵称34");
        userInfo.setGender(GenderEnum.MALE);
        userInfoMapper.insert(userInfo);
        propagationService.notSupportedTransactional();
    }

}
